from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import pickle

url="https://gitee.com/login?redirect_to_url=%2F"
driver = webdriver.Chrome()
driver.get(url)

# 输入用户名和密码
username_input = driver.find_element(By.XPATH, '//*[@id="user_login"]')
password_input = driver.find_element(By.XPATH, '//*[@id="user_password"]')
username_input.send_keys("18242953778")  # 替换为你的用户名
password_input.send_keys("LijianQi2001")  # 替换为你的密码
print("登录中")
# 单击登录按钮
login_button = driver.find_element(By.XPATH, '//*[@class="ui fluid orange submit button large"]').click()
print("单击登录按钮")
# 等待登录操作完成，可选，根据实际情况调整等待时间
time.sleep(10)
# 保存Cookies
cookies = driver.get_cookies()
print(cookies[0])
with open('gitee_cookies.txt', 'wb') as filehandler:
    pickle.dump(cookies, filehandler)
print("登录成功，Cookies已保存。")
# 关闭浏览器
driver.quit()